package cn.ecommerce.course.module.users.controller.app.users;


import cn.ecommerce.course.framework.common.pojo.CommonResult;
import cn.ecommerce.course.module.users.controller.app.users.dto.LoginDTO;
import cn.ecommerce.course.module.users.controller.app.users.dto.LoginResponseDTO;
import cn.ecommerce.course.module.users.service.users.UsersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Tag(name = "管理后台 - 电商平台用户")
@RestController
@RequestMapping("/users")
@Validated
public class AppUsersController {

    @Resource
    private UsersService usersService;

    @PostMapping("/getCode")
    @Operation(summary = "获取验证码")
    public CommonResult<Boolean> getCode(@RequestBody LoginDTO loginDTO) {
       return usersService.sendCode(loginDTO);
    }

    @PostMapping("/verifyCodeLogin")
    @Operation(summary = "手机验证码登录")
    public CommonResult<LoginResponseDTO> verifyCodeLogin(@RequestBody LoginDTO loginDTO){
        return usersService.verifyCodeLogin(loginDTO);
    }

    @PostMapping("/accountLogin")
    @Operation(summary = "账号密码登录")
    public CommonResult<LoginResponseDTO> accountLogin(@RequestBody LoginDTO loginDTO){
        return usersService.accountLogin(loginDTO);
    }

    @PostMapping("/logout")
    @Operation(summary = "退出登录")
    public CommonResult<Boolean> logout(@RequestBody LoginResponseDTO loginResponseDTO){
        return usersService.logout(loginResponseDTO);
    }
}
